package com.xjrsoft.module.customerTwo.aiplm.t_aiplm_design.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.page.ConventPage;
import java.util.List;
import com.xjrsoft.common.utils.DataTransUtil;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.secure.XjrUser;
import com.xjrsoft.core.secure.utils.SecureUtil;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_design.dto.TAiplmDesignDto;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_design.dto.SaveTAiplmDesignFormDataDto;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_design.vo.TAiplmDesignVo;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_design.vo.TAiplmDesignListVo;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_design.dto.TAiplmDesignListDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import org.springframework.web.bind.annotation.*;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_design.entity.TAiplmDesign;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_design.vo.TAiplmDesignVo;
import com.xjrsoft.module.customerTwo.aiplm.t_aiplm_design.service.ITAiplmDesignService;

/**
 *  控制器
 *
 * @author dongxinhang
 * @since 2024-07-08
 */
@RestController
@AllArgsConstructor
@RequestMapping("/t_aiplm_design")
@Api(value = "我的设计", tags = "我的设计接口")
public class TAiplmDesignController {


	private final ITAiplmDesignService tAiplmDesignService;


	/**
	 * 详情 
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入tAiplmDesign")
	@SaCheckPermission(value = {"t_aiplm_design:view", "t_aiplm_design:modify"}, mode = SaMode.OR)
	public Response<TAiplmDesignVo> getFormData(@PathVariable String id) {
		// 主表数据
		TAiplmDesign tAiplmDesign = tAiplmDesignService.getById(id);
		TAiplmDesignVo tAiplmDesignVo = BeanUtil.copy(tAiplmDesign, TAiplmDesignVo.class);
		return Response.ok(tAiplmDesignVo);
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入tAiplmDesign")
		public Response<PageOutput<TAiplmDesignListVo>> getPageList(TAiplmDesignListDto listDto) {
		XjrUser currentUser = SecureUtil.getUser();
		if(!currentUser.isAdminUser()){	//非系统管理员只能查看自己的设计
			listDto.setF_CreateUserId(currentUser.getUserId());
		}
		IPage<TAiplmDesign> page = tAiplmDesignService.queryPage(new Page<>(listDto.getLimit(), listDto.getSize()),listDto);
		List<TAiplmDesignListVo> records = BeanUtil.copyList(page.getRecords(), TAiplmDesignListVo.class);
			// 转换列表数据
		DataTransUtil.transListShowData(records);
		return Response.ok(ConventPage.getPageOutput(page.getTotal(), records));
	}

	/**
	 * 新增 
	 */
	@PostMapping
	@ApiOperation(value = "新增", notes = "传入tAiplmDesign")
	@SaCheckPermission("t_aiplm_design:add")
	public Response save(@RequestBody SaveTAiplmDesignFormDataDto formDto) {
		TAiplmDesignDto tAiplmDesignDto = formDto.getTAiplmDesignDto();
		TAiplmDesign tAiplmDesign = BeanUtil.copy(tAiplmDesignDto, TAiplmDesign.class);
		boolean isSuccess = tAiplmDesignService.addTAiplmDesign(tAiplmDesign);
		return Response.status(isSuccess);
	}

	/**
	 * 修改 
	 */
	@PutMapping("/{id}")
	@ApiOperation(value = "修改", notes = "传入tAiplmDesign")
	@SaCheckPermission("t_aiplm_design:modify")
	public Response update(@PathVariable String id, @RequestBody SaveTAiplmDesignFormDataDto formDto) {
		TAiplmDesignDto tAiplmDesignDto = formDto.getTAiplmDesignDto();
		TAiplmDesign tAiplmDesign = BeanUtil.copy(tAiplmDesignDto, TAiplmDesign.class);
		return Response.status(tAiplmDesignService.updateTAiplmDesign(id, tAiplmDesign));
	}



	/**
	 * 删除 
	 */
	@DeleteMapping("/{ids}")
	@ApiOperation(value = "删除", notes = "传入ids")
	@SaCheckPermission(value = {"t_aiplm_design:batchDelete", "t_aiplm_design:delete"}, mode = SaMode.OR)
	public Response remove(@ApiParam(value = "主键集合", required = true) @PathVariable String ids) {
		return Response.status(tAiplmDesignService.delete(ids));
	}


}
